﻿<%@ page language="java" contentType="text/html; charset=UTF-8"
		 pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	response.setContentType("text/html;charset=utf-8");
	response.setCharacterEncoding("utf-8");
%>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="copyright" content="" />
	<meta name="keywords" content="" />
	<meta name="description" content="" />
	<title>模板管理</title>
	<link href="<%=path%>/favicon.ico" rel="shortcut icon">

	<link rel="stylesheet" type="text/css"
		  href="<%=path%>/css/marketing/public.css" />
	<link rel="stylesheet" type="text/css"
		  href="<%=path%>/css/marketing/style_list.css" />


	<link href="<%=path%>/hplus/css/bootstrap.min14ed.css?v=3.3.6" rel="stylesheet">
	<link href="<%=path%>/hplus/css/font-awesome.min93e3.css?v=4.4.0" rel="stylesheet">
	<link href="<%=path%>/hplus/css/plugins/iCheck/custom.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/animate.min.css" rel="stylesheet">
	<link href="<%=path%>/hplus/css/style.min862f.css?v=4.1.0" rel="stylesheet">
	<link rel="stylesheet" type="text/css" href="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.css">
	<link href="<%=path%>/css/marketing/s_style.css" rel="stylesheet">

	<!--以下两行加载秀米的ueditor插件的脚本和CSS，请编辑您的UEditor网页加入他们-->
	<!--您也可以下载这两个文件并根据您的需要改动相关的内容，当然，改动后您必须将新文件存放到您的服务器上了-->
	<link rel="stylesheet" href="http://xiumi.us/connect/ue/v5/xiumi-ue-v5.css">
	<style type="text/css">
		#edui1 {
			width: 550px !important;
			height: 870px !important;
		}
		#edui1_iframeholder {
			width: 550px !important;
			height: 740px !important;
		}
		#edui3_body{
			display: none;
		}
	</style>

</head>
<body class="gray-bg" id="parentBody">
<div class="wrapper wrapper-content animated fadeInRight">
	<div class="container-fluid">
		<div class="row">
			<div class="col-md-12" id="buzhou" hidden="">
				<div class="x_progress s_big">
					<div class="s_line">
						<div class="s_progress_bar s_current" role="progressbar"
							 aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
							<span class="sr-only_1">1</span>
							<p class="x_color_bz">选择模板</p >
						</div>
						<div class="s_progress_bar s_current" role="progressbar"
							 aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
							<span class="sr-only_2">2</span>
							<p class="x_color_bz">编辑内容</p >
						</div>
						<div class="s_progress_bar" role="progressbar"
							 aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
							<span class="sr-only_3">3</span>
							<p class="x_color_bz">成功提示页</p >
						</div>
						<div class="s_progress_bar" role="progressbar"
							 aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
							<span class="sr-only_3">4</span>
							<p class="x_color_bz">分享设置</p >
						</div>
						<div class="s_progress_bar" role="progressbar"
							 aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
							<span class="sr-only_4">5</span>
							<p class="x_color_bz">活动预览</p >
						</div>
						<div class="s_progress_bar" role="progressbar"
							 aria-valuenow="60" aria-valuemin="0" aria-valuemax="100">
							<span class="sr-only_5">6</span>
							<p class="x_color_bz">分享</p >
						</div>
					</div>
				</div>
			</div>
			<div class="col-md-12 white-bg" style="padding:20px">
				<!--内容左侧-->
				<div id="left_content" class="col-md-6 text-center">
					<div class="row">
						<div class="col-md-12 k_activity">
							<div id="editor"></div>

							<!-- <h3>&nbsp;</h3> -->
							<form method="get" class="form-horizontal m-t commithtml text-center">

							</form>
							<button id="create_model" type="button"  style="width:200px;margin-left:10px" class=" btn btn-w-m btn-danger s_get_btn">立即领取</button>
						</div>

						<ul class="col-md-12 s_footer" style="margin-top:80px">
							<li class="previewWeiXin col-md-6"><img src="<%=path%>/images/marketing/icon_wb.png"
																	id="erweima_weixin2" style="width:79px;height:79px;"/>
								<p>微信二维码</p></li>
							<li class="previewWeiBo col-md-6"><img src="<%=path%>/images/marketing/icon_wb.png"
																   id="erweima_weibo2"  style="width:79px;height:79px;"/>
								<p>微博二维码</p></li>
						</ul>

					</div>
				</div>
				<!--活动预览部分end-->
				<div class="col-md-6" >
					<div class="row">
						<form method="get" class="form-horizontal m-t text-center">
							<div class="form-group col-md-12 ">
								<p class="col-sm-3 text-right" id="title_name" style="margin-top:10px;">活动名称</p>
								<div class="col-sm-6" style="margin-left:-12px;">
									<input type="text" class="form-control" id="firstname"
										   placeholder="不超过25个字" maxlength="25" onblur="checkLength(this)">
								</div>
							</div>
							<div class="form-group col-md-12 text-left">
								<p class="col-sm-3 text-right" style="margin-top:12px">地址信息</p>

								<div class="panel panel-default  col-sm-6">
									<div class="panel-body">
										<ul id="bm_md_list">

										</ul>
									</div>
								</div>
								<a  class="col-sm-2" style="color: #03a9f4;margin-top:12px"  data-toggle="modal" href="<%=path%>/view/ui/store" data-target="#store_modal">
									选择门店
								</a>
							</div>
							<div class="coupon-model-class form-group col-md-12 text-left">
								<p class="col-sm-3 text-right"  style="margin-top:10px;">优惠券信息</p>
								<div class="panel panel-default  col-sm-6">
									<div class="panel-body">
										<ul id="couponModelList">

										</ul>
									</div>
								</div>
								<a  class="col-sm-3" style="color: #03a9f4;margin-top:10px"  data-toggle="modal" href="<%=path%>/view/ui/modalCouponMultiple" data-target="#coupon_modal" data-backdrop="static" data-keyboard="false">
									选择优惠券
								</a>
							</div>
							<div class="col-md-12" style="margin-top:-20px">
								<h1 class="col-md-3"></h1>
								<h1 class="col-md-3"></h1>
							</div>
							<div class="coupon-model-class form-group col-md-12 ">
								<p class="col-sm-3 text-right"  style="margin-top:10px;">通知客户方式</p>
								<div  class="col-sm-9 text-left" style="margin-left:-12px">
									<label class="checkbox-inline i-checks sendType" >
										<input type="checkbox"  id="send_sms">短信</label>
									<label style="display:none;" class="checkbox-inline i-checks sendType" >
										<input type="checkbox"  id="send_email">邮箱</label>
								</div>
							</div>
							<div class="coupon-model-class form-group col-md-12 text-left" >
								<p class="col-md-3 text-right"></p>
								<textarea id="sms_content" class="panel panel-default panel-body col-sm-6" maxlength="100" onblur="checkLength(this)" placeholder="此文本用于用户提交表单收到的短信内容"></textarea>
							</div>

							<div class="form-group col-md-12 ">
								<p class="col-sm-3 text-right" id="title_name" style="margin-top:10px;">添加标签</p>
								<div class="col-sm-6" style="margin-left:-12px;">
									<input id="activity_tag" type="text" class="form-control"
										   placeholder="" maxlength="25" onblur="checkLength(this)">
								</div>
							</div>


							<div class="form-group">
								<p class="col-sm-3 text-right" id="title_name" style="margin-top:10px;">背景颜色</p>
								<div class="btn-group k_color_box text-left col-sm-9 k_color" style="margin-left:-10px">
									<div class="k_color">
										<img src="<%=path%>/images/marketing/ha.png"> <span class="caret" data-toggle="dropdown" style="float:right;margin:8px 5px;"></span>
										<input id="bgd_color" type="color" onchange="reloadBackground()" style="opacity:0;position:absolute;top:0;width:100px;">
									</div>
								</div>
							</div>

							<div class="form-group col-md-12 ">
								<p class="col-sm-3 text-right"  style="margin-top:10px;">收集信息</p>
								<div id="commit_parent" class="col-sm-9 text-left" style="margin-left:-12px">
									<label class="checkbox-inline i-checks commit" id="commit_name" onclick="testO()">
										<input type="checkbox" value="commit_name" id="input_name">姓名</label>
									<label class="checkbox-inline i-checks commit" id="commit_mobile">
										<input type="checkbox" value="commit_mobile" id="input_mobile">电话</label>
									<label class="checkbox-inline i-checks commit" id="commit_email">
										<input type="checkbox" value="commit_email" id="input_email">邮箱</label>
									<label class="checkbox-inline i-checks commit" id="commit_weibo">
										<input type="checkbox" value="commit_weibo" id="input_weibo1">微博</label>
									<label class="checkbox-inline i-checks commit" id="commit_weixin">
										<input type="checkbox" value="commit_weixin" id="input_weixin1">微信</label>
									<label class="checkbox-inline i-checks commit" id="commit_job">
										<input type="checkbox" value="commit_job" id="input_job">职位</label>
									<label class="checkbox-inline i-checks commit" id="commit_company">
										<input type="checkbox" value="commit_company" id="input_company">公司</label>
								</div>
							</div>

							<div class="form-group col-md-12 ">
								<p class="col-sm-3 text-right"  style="margin-top:10px;"></p>
								<small class="col-sm-6 text-left" style="margin-left:-12px">建议不超过勾选3项，否则影响转化率</small>
							</div>

							<div class="form-group col-md-12 ">
								<p class="col-sm-3 text-right"  style="margin-top:10px;">设置按钮</p>

								<span class="col-sm-2 text-left" id="title_name" style="margin-top:10px;">按钮颜色</span>
								<div class="btn-group k_color_box text-left col-sm-2 k_color" style="margin-left:-15px">
									<div class="k_color">
										<img src="<%=path%>/images/marketing/ha.png"> <span class="caret" data-toggle="dropdown" style="float:right;margin:8px 5px;"></span>
										<input id="btn_color" type="color" onchange="reloadLeft()" style="opacity:0;position:absolute;top:0;width:100px;">
									</div>
								</div>
							</div>
							<div class="form-group col-md-12 ">
								<p class="col-sm-3 text-right"  ></p>
								<span class="col-sm-2 text-left" style="margin-left:-10px;margin-top:10px">按钮文本</span>
								<div class="col-sm-6" style="margin-left:-12px;">
									<input type="text" class="form-control" name="textfield" id="textfield" oninput="reloadLeft()" maxlength="6" onblur="checkLength(this)">
								</div>
							</div>

						</form>

						<div class=" col-md-12">
							<p class=" col-md-3 text-right" style="margin-left:-10px;margin-top:12px" id="set_button1" >页脚信息</p>
							<div class="row col-md-9" style="margin-left:-20px;margin-top:-5px">
								<form id='_weixin_qrcode' action="post" class="form-vertical m-t text-left col-md-6" enctype='multipart/form-data'>
									<div class="row">
										<div class="x_img_sc">
											<img id="img4" src="<%=path%>/images/marketing/img_p.png" style="width:100px;height:100px;">
										</div>
										<input type="file" accept="image/gif,image/jpeg,image/x-png" id="x_inputfile"  name="filepath" fileType="weixin"
											   style="filter: alpha(opacity = 50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.0; position: absolute; z-index: 99;">
									</div>
									<label class="checkbox-inline i-checks labWeiXin" style="margin-left:-9px;margin-top:5px"><input id="input_weixin" type="checkbox" value="option1" >微信二维码</label>
								</form>

								<form  id='_weibo_qrcode' enctype='multipart/form-data' action="post" class="form-vertical m-t text-left col-md-6">
									<div class="row">
										<div class="x_img_sc">
											<img id="img5" src="<%=path%>/images/marketing/img_p.png"  style="width:100px;height:100px;"/>
										</div>
										<input type="file" accept="image/gif,image/jpeg,image/x-png" id="x_inputfile" fileType="weibo" name="filepath"
											   style="filter: alpha(opacity = 50); -moz-opacity: 0.5; -khtml-opacity: 0.5; opacity: 0.0; position: absolute; z-index: 99;" />
									</div>
									<label class="checkbox-inline i-checks labWeiBo" style="margin-left:-9px;margin-top:5px"><input id="input_weibo" type="checkbox" value="option1">微博二维码</label>
								</form>
							</div>
						</div>

						<div class="col-md-12">
							<div class="col-sm-3"></div>
							<div class="col-sm-7" style="margin-left:-24px;margin-top:25px">
								<button id="x_button_l" type="button" class="btn btn-primary btn-outline">取消</button>
								<button id="x_button_y" type="button" class="btn  btn-warning " style="margin-left:10px">暂存</button>
								<button id="x_button_bm" type="button" class="btn  btn-primary " style="margin-left:25px">下一步</button>
							</div>
						</div>







						<!-- <div class="x_top10">
                            <a class="x_button_l" style="color: #03a9f4;"
                                href="javascript:;">取消</a> <a class="x_button_y"
                                href="javascript:;">暂存</a> <a id="x_button_bm" class="x_button"
                                href="javascript:;">下一步</a>
                        </div> -->
					</div>
				</div>

			</div>

		</div>
	</div>
</div>






<div class="modal inmodal fade" id="store_modal" tabindex="-1" role="dialog"  aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">

		</div>
	</div>
</div>

<div class="modal inmodal fade" id="coupon_modal" tabindex="-1" role="dialog"  aria-hidden="true">
	<div class="modal-dialog modal-lg">
		<div class="modal-content">

		</div>
	</div>
</div>



<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>

<script type="text/javascript" src="<%=path%>/js/marketing/ajaxfileupload.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/marketing/lengthlimit.js"></script>

<script src="<%=path%>/hplus/js/plugins/sweetalert/sweetalert2.min.js"></script>
<script src="<%=path%>/hplus/js/jquery.min.js?v=2.1.4"></script>
<script src="<%=path%>/hplus/js/bootstrap.min.js?v=3.3.6"></script>
<script src="<%=path%>/hplus/js/plugins/chosen/chosen.jquery.js"></script>
<script src="<%=path%>/hplus/js/plugins/jsKnob/jquery.knob.js"></script>
<script src="<%=path%>/hplus/js/plugins/jasny/jasny-bootstrap.min.js"></script>
<script src="<%=path%>/hplus/js/plugins/datapicker/bootstrap-datepicker.js"></script>
<script src="<%=path%>/hplus/js/plugins/prettyfile/bootstrap-prettyfile.js"></script>
<script src="<%=path%>/hplus/js/plugins/switchery/switchery.js"></script>
<script src="<%=path%>/hplus/js/plugins/ionRangeSlider/ion.rangeSlider.min.js"></script>
<script src="<%=path%>/hplus/js/plugins/iCheck/icheck.min.js"></script>
<script src="<%=path%>/hplus/js/plugins/metisMenu/jquery.metisMenu.js"></script>
<script src="<%=path%>/hplus/js/plugins/colorpicker/bootstrap-colorpicker.min.js"></script>
<script src="<%=path%>/hplus/js/plugins/clockpicker/clockpicker.js"></script>
<script src="<%=path%>/hplus/js/plugins/cropper/cropper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
<script src="<%=path%>/hplus/js/demo/form-advanced-demo.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/marketing/dialog.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.16/js/jquery.dataTables.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js"></script>
<script type="text/javascript" src="<%=path%>/js/marketing/public.js"></script>

<!-- 配置文件 -->
<script type="text/javascript" src="<%=path%>/js/material/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="<%=path%>/js/material/ueditor/ueditor.all.js"></script>
<script type="text/javascript" src="<%=path%>/js/material/ueditor/ueditor.parse.js"></script>
<script type="text/javascript" src="<%=path%>/js/material/ueditor/lang/zh-cn/zh-cn.js"></script>
<%-- <script type="text/javascript" src="<%=path%>/js/material/ueditor/xiumi-ue-dialog-v5.js"/> --%>
<script type="text/javascript" charset="utf-8" src="<%=path%>/js/material/ueditor/xiumi-ue-dialog-v5.js"></script>

<%-- ckeditor js --%>
<%--<script type="text/javascript"  src="<%=path%>/js/marketing/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="<%=path%>/js/marketing/ckeditor/sample.js"></script>--%>

<script type="text/javascript">

    /* $("#commit_name").bind('DOMNodeInserted', function(e) {
        console.log("你是不是傻");
    });
     */

    $('.commit').on('ifChecked', function(event){
        $(this).children().addClass("checked");
        reloadLeft();
    });
    $('.commit').on('ifUnchecked', function(event){
        $(this).children().removeClass("checked");
        reloadLeft();
    });

    $('.sendType').on('ifChecked', function(event){
        $(this).children().addClass("checked");
        reloadLeft();
    });
    $('.sendType').on('ifUnchecked', function(event){
        $(this).children().removeClass("checked");
        reloadLeft();
    });

    $('.labWeiXin').on('ifChecked', function(event){
        $(this).children().addClass("checked");
        choseQrWeixinFlag=true;
        reloadLeft();
    });
    $('.labWeiXin').on('ifUnchecked', function(event){
        $(this).children().removeClass("checked");
        choseQrWeixinFlag=false;
        reloadLeft();
    });

    $('.labWeiBo').on('ifChecked', function(event){
        $(this).children().addClass("checked");
        choseQrWeiboFlag=true;
        reloadLeft();
    });
    $('.labWeiBo').on('ifUnchecked', function(event){
        $(this).children().removeClass("checked");
        choseQrWeiboFlag=false;
        reloadLeft();
    });



    $(".x_CheckBox_pic").click(function () {
        var cutsrc = $(".x_CheckBox_pic").attr('src');
        if (cutsrc == "<%=path%>/images/marketing/s_check_no.png") {
            $(".x_CheckBox_pic").attr('src', '<%=path%>/images/marketing/s_check.png');
            $(".ibox-content").find(".x_CheckBox").attr('src', '<%=path%>/images/marketing/s_check.png');
        } else {
            $(".x_CheckBox_pic").attr('src', '<%=path%>/images/marketing/s_check_no.png');
            $(".ibox-content").find(".x_CheckBox").attr('src', '<%=path%>/images/marketing/s_check_no.png');
        }
    });

    /* ckeditor相关   --start */
    /* initSample(); */

    /*lg*/
    /*var editor = CKEDITOR.replace('editor', {
        "filebrowserUploadUrl" : "${pageContext.request.contextPath}/api/uploadfile/uploadCKImg",
			enterMode :CKEDITOR.ENTER_BR //换行直接加br
		});
		*/
    window.UEDITOR_HOME_URL = "<%=path%>" ;
    var editor = UE.getEditor('editor');


    /* function save(){
        showDialogr.updateElement(); //非常重要的一句代码
        //前台验证工作
        //提交到后台
        return true ;
    } */
    /* ckeditor相关  --end */

    function reloadBackground(){
        background_color=$('#bgd_color').val();
        $(".s_left_phone").css("background-color",background_color);
        $("#left_content").css("background-color",background_color);
        $("#cke_1_bottom").css("background-color",background_color);
        CKEDITOR.addCss(".cke_editable{background-color: "+background_color+"}");
    }

    $('img').error(function(){
        $(this).attr('src', '<%=path%>/images/marketing/img_load_error.png');
    });

    $('.commit').click(function(){
        reloadLeft();
    });

    function testO(){
    }




    $(document).on("#textfield",function(e){
        reloadLeft();
    });

    var choseQrWeixinFlag=false;
    var choseQrWeiboFlag=false;
    var commit_info = "";
    function reloadLeft() {
        $(".k_activity>.s_name_input").remove();
        $(".k_activity>.s_phone_input").remove();
        commit_info="";
        var commitHtml='';
        $(".commit .checked").children()
            .each(
                function(i, d) {
                    if(StringEmpty(this.id)){
                        var name = $.trim($(this).parent().parent().text());
                        commitHtml+='<div class="form-group"><label class="col-sm-5	 control-label">'+name+'</label><div class="col-sm-7"><input style="width:40%;" id="phone" type="text" class="form-control" required="" aria-required="true"></div></div>';
                        commit_info = commit_info + "," +this.value;
                    }
                });

        $('.commithtml').html(commitHtml);
        commit_info = commit_info.replace(",", "");

        send_type="";
        $(".sendType .checked").children()
            .each(
                function(i, d) {
                    if(StringEmpty(this.id)){
                        send_type=send_type+","+this.id;}
                });

        send_type = send_type.replace(",", "");

        var color=document.getElementById('btn_color').value;
        var btn_text=$("#textfield").val();
        if(color!="#000000")
            $(".s_get_btn").css("background-color",color);
        if(StringEmpty(btn_text))
            $(".s_get_btn").html(btn_text);
        if(StringEmpty(commit_info)){
            $(".s_get_btn").show();
        }else{
            $(".s_get_btn").hide();
        }
        if(!choseQrWeiboFlag&&choseQrWeixinFlag){
            $('.previewWeiBo').hide();
            $('.previewWeiXin').show();
            $('.previewWeiXin').removeClass("col-md-6");
            $('.previewWeiXin').addClass("col-md-12");
        }else if(choseQrWeiboFlag&&!choseQrWeixinFlag){
            $('.previewWeiXin').hide();
            $('.previewWeiBo').show();
            $('.previewWeiBo').removeClass("col-md-6");
            $('.previewWeiBo').addClass("col-md-12");
        }else if(!choseQrWeiboFlag&&!choseQrWeixinFlag){
            $('.previewWeiXin').hide();
            $('.previewWeiBo').hide();
        }else{
            $('.previewWeiBo').removeClass("col-md-12");
            $('.previewWeiXin').removeClass("col-md-12");
            $('.previewWeiBo').addClass("col-md-6");
            $('.previewWeiXin').addClass("col-md-6");
            $('.previewWeiXin').show();
            $('.previewWeiBo').show();
        }



    }

    //点击选择门店弹框
    $('#bm_cmen').click(function(){
        $('.x_popup_add,.issue_add').show();
    });
    //点击添加门店
    $(".x_button_add").click(function () {
        $('#bm_qming').val('');
        $('#bm_qaddress').val('');
        $('#bm_qphone').val('');
        $(".x_popup_t,.issue_t").show();
        $(".x_popup_editor,.issue_editor").hide();
    })


    $('.k_ty_btn').click(function(){
        $('.s_popup_delect1,.issue_delect1').show();
    });

    $('.s_cancel1,.issue_delect1 span').click(function(){
        $('.s_popup_delect1,.issue_delect1').hide();
    });

    var couponModalStatus=false;
    //监听优惠券模态款打开状态
    $('#coupon_modal').on('show.bs.modal', function () {
        couponModalStatus=true;
    });
    function colsecouponNotEnough(){
        $('#couponNotEnough').modal("hide");
    }
</script>

<script type="text/javascript">
    $.fn.dataTable.ext.errMode = 'none';
    var access_token=$.cookie('access_token');
    var cid=$.cookie('cid');
    var uid=$.cookie('uid');
    var model_id;
    var activity_id;
    var model_type="defined_text";
    var title;
    var weibo_qrcode;
    var weixin_qrcode;

    //标记是执行的是创建活动还是创建模板
    var type;
    //是否保存标记
    var save_tag=false;


    var button_color;
    var button_text;
    var text_info;

    var next_flag;
    var sms_content;
    var status="2";
    var modelType="defined";
    var background_color;

    var storeId="";
    //关键字
    var store_names=new Array();
    var store_ids=new Array();
    var mdstore;


    var couponName="";
    var couponId="";
    var tempCouponId="";

    var activityTag;
    var save_actiivty_tag=false;
    var send_type="";

    /* 优惠券类型标记    0表示使用平台优惠券  1表示使用第三方优惠券 */
    var couponIdsMap=new Map();
    var couponIds=new Array();
    var thirdPartyCouponIdsMap=new Map();
    var thirdPartyCouponIds=new Array();

    var couponNameMap=new Map();
    var thirdCouponNameMap=new Map();

    var couponFlag=0;
    var couponModelType=0;
    var tempCouponModelType=0;
    var couponModelIds="";
    var operationType="";
    //初始化
    $(function(){
        $(".i-checks").iCheck({checkboxClass:"icheckbox_square-green",radioClass:"iradio_square-green",});

        activity_id=getQueryString("activity_id");
        model_id=getQueryString("model_id");
        type=getQueryString("type");
        modelType=getQueryString("modelType");
        operationType=getQueryString("operationType");
        if(StringEmpty(model_id)){
            if(modelType=="sys"){
                getSysModelInfo(model_id);
            }else{
                getModelInfo(model_id);
                modelStore();
            }

        }
        pushHistory();
        window.addEventListener("popstate", function(e) {
            if(type=="model"&&StringEmpty(model_id)){
                history.go(-1);
            }else{
                history.go(-1);
            }
        }, false);


        if((type=="model"||type=="model_copy")){
            $('.coupon-model-class').hide();
            $(document).attr("title","模板编辑");
            $('#set_button1').show();
            $('#set_button2').show();

            $('#title_name').html("模板名称");

            $("#x_button_bm").text("预览");
            $("#x_button_y").text("保存");
            $(".k_radio").show();

        }else if(type=="activity"||type=="activity_copy"||type=="both" ){
            $('#buzhou').show();
            $(document).attr("title","活动编辑");

            $('#title_name').html("活动名称");
            if(StringEmpty(activity_id)){
                getActivityInfo(activity_id);
                activityStore();
            }else{
                $(".s_get_btn").hide();
            }

        }else{
            $('.coupon-model-class').hide();
            $("#x_button_bm").text("预览");
            $(".k_radio").show();
            $("#x_button_y").text("保存");
            reloadLeft();
        }
    });
    //保存
    $('#x_button_y').click(function () {


        save();
    });
    //下一步
    $('#x_button_bm').click(function () {

        next_flag=true;
        save();



    });
    //获取模板信息
    function getModelInfo(model_id) {
        var url = "<%=path%>/activityDefinedTemplate/ajaxTemplateDetail";
        $.post(url, {
            "access_token" : access_token,
            "uid" : uid,
            "id" : model_id,
        }, function(data) {

            if (data.status == 200) {
                intModelHtml(data.data);
            } else {
                errorDialog("获取数据失败","");
            }
        });
    }
    //获取系统模板信息
    function getSysModelInfo(model_id) {
        var url = "<%=path%>/activitySysModel/ajaxActivitySysyModelDetail";
        $.post(url, {
            "access_token" : access_token,
            "uid" : uid,
            "id" : model_id,
        }, function(data) {

            if (data.status == 200) {
                intModelHtml(data.data);
            } else {
                errorDialog("获取数据失败","");
            }
        });
    }

    //获取活动信息
    function getActivityInfo(activity_id) {
        var url="<%=path%>/activity/ajaxActivityDetailAndCouponList";
        $.post(url, {
            "access_token" : access_token,
            "uid" : uid,
            "id" : activity_id,
        }, function(data) {

            if (data.status == 200&&data.data!=undefined) {
                initActivityHtml(data.data);
                initCouponModelHtml(data.data.couponFlag,data.couponModelData);
            } else {
                errorDialog("获取数据失败","");

            }
        });

    }

    function initCouponModelHtml(couponModelType,couponModelDatas){
        if(couponModelDatas.length>0){
            var html="";
            for(var i=0;i<couponModelDatas.length;i++){
                var couponModelData=couponModelDatas[i];
                if(couponModelType==1){
                    thirdPartyCouponIdsMap.set(couponModelData.couponModelId+"",couponModelData.couponModelId);
                    thirdCouponNameMap.set(couponModelData.couponModelId,couponModelData.couponModelName);
                    couponIds.push(couponModelData.couponModelId);
                    thirdPartyCouponIds.push(couponModelData.couponModelId);
                }else{
                    couponIdsMap.set(couponModelData.couponModelId+"",couponModelData.couponModelId);
                    couponNameMap.set(couponModelData.couponModelId,couponModelData.couponModelName);
                    couponIds.push(couponModelData.couponModelId);
                }
                html += '<li id="couponModelline'+couponModelData.couponModelId+'" indexNum="'+couponModelData.couponModelId+'" class="delete_md_detail  col-md-6 text-left" >'+couponModelData.couponModelName+'<img indexNum="'+couponModelData.couponModelId+'" cid="'+couponModelData.couponModelId+'" src="<%=path%>/images/marketing/close.png" class="x_lista delCouponModel"></li>';
            }
            $('#couponModelList').html(html);
        }
    }

    //设置活动html
    function initActivityHtml(data){
        document.getElementById('firstname').value = data.name;
        status=data.status;
        //设置领券所需提交信息
        if(StringEmpty(data.commitInfo)){
            var commit_infos=data.commitInfo;
            var commits=commit_infos.split(",");
            for(var i in commits){
                if(commits[i]=="commit_name"){
                    $("#input_name").attr("checked","checked");
                    $("#commit_name").children().addClass("checked");
                }
                if(commits[i]=="commit_mobile"){
                    $("#input_mobile").attr("checked","checked");
                    $("#commit_mobile").children().addClass("checked");
                }

                if(commits[i]=="commit_email"){
                    $("#input_email").attr("checked","checked");
                    $("#commit_email").children().addClass("checked");
                }

                if(commits[i]=="commit_weibo"){
                    $("#input_weibo1").attr("checked","checked");
                    $("#commit_weibo").children().addClass("checked");
                }

                if(commits[i]=="commit_weixin"){
                    $("#input_weixin1").attr("checked","checked");
                    $("#commit_weixin").children().addClass("checked");
                }

                if(commits[i]=="commit_job"){
                    $("#input_job").attr("checked","checked");
                    $("#commit_job").children().addClass("checked");
                }

                if(commits[i]=="commit_company"){
                    $("#input_company").attr("checked","checked");
                    $("#commit_company").children().addClass("checked");
                }
            }
        }
        //设置按钮文本
        document.getElementById('textfield').value = data.buttonText;
        //设置按钮颜色
        document.getElementById('btn_color').value = data.buttonCss;
        //设置二维码
        if(StringEmpty(data.weiboQrcode)){
            weibo_qrcode=data.weiboQrcode;
            choseQrWeiboFlag=true;

            $('#input_weibo').parent().addClass("checked");
            $("#input_weibo").attr("checked","checked");
            document.getElementById('img5').src = data.weiboQrcode;
            document.getElementById('erweima_weibo2').src = data.weiboQrcode;

        }
        if(StringEmpty(data.weixinQrcode)){
            weixin_qrcode=data.weixinQrcode;
            choseQrWeixinFlag=true;
            document.getElementById('img4').src = data.weixinQrcode;
            $('#input_weixin').parent().addClass("checked");
            $("#input_weixin").attr("checked","checked");
            document.getElementById('erweima_weixin2').src = data.weixinQrcode;
        }
        sms_content=data.smsContent;
        if(StringEmpty(sms_content))
            $('#sms_content').val(sms_content);


        if(StringEmpty(data.remarks)){
            $('#bgd_color').val(data.remarks);
            reloadBackground();
        }

        reloadLeft();
        setTimeout(function () {
            var ckcontent = data.description;
            //CKEDITOR.instances.editor.setData(ckcontent);
            editor.setContent(ckcontent);
        }, 1000);

        couponName=data.couponName;
        couponId=data.couponId;
        tempCouponId=couponId;
        if(StringEmpty(couponName)){
            $("#couponNane").val(couponName);
        }
        activityTag=data.tagDefined;
        if(StringEmpty(activityTag)){
            $('#activity_tag').val(activityTag);
        }
        couponFlag=data.couponFlag;
        tempCouponFlag=couponFlag;
        couponModelType=tempCouponFlag;
        tempCouponModelType=couponModelType;
        send_type=data.couponSendType;
        //设置优惠券发送方式
        if(StringEmpty(data.couponSendType)){
            var send=data.couponSendType;
            var sendTypes=send.split(",");
            for(var i in sendTypes){
                if(sendTypes[i]=="send_sms"){
                    $('#send_sms').parent().addClass("checked");
                    $("#send_sms").attr("checked","checked");
                }
                if(sendTypes[i]=="send_email"){
                    $('#send_email').parent().addClass("checked");
                    $("#send_email").attr("checked","checked");
                }
            }
        }


    }
    //设置模板html
    function intModelHtml(data) {
        document.getElementById('firstname').value = data.name;
        //设置领券所需提交信息
        if(StringEmpty(data.collectInfo)){
            var commit_infos=data.collectInfo;
            var commits=commit_infos.split(",");
            for(var i in commits){
                if(commits[i]=="commit_name"){
                    $("#input_name").attr("checked","checked");
                    $("#commit_name").children().addClass("checked");
                }
                if(commits[i]=="commit_mobile"){
                    $("#input_mobile").attr("checked","checked");
                    $("#commit_mobile").children().addClass("checked");
                }

                if(commits[i]=="commit_email"){
                    $("#input_email").attr("checked","checked");
                    $("#commit_email").children().addClass("checked");
                }

                if(commits[i]=="commit_weibo"){
                    $("#input_weibo1").attr("checked","checked");
                    $("#commit_weibo").children().addClass("checked");
                }

                if(commits[i]=="commit_weixin"){
                    $("#input_weixin1").attr("checked","checked");
                    $("#commit_weixin").children().addClass("checked");
                }

                if(commits[i]=="commit_job"){
                    $("#input_job").attr("checked","checked");
                    $("#commit_job").children().addClass("checked");
                }

                if(commits[i]=="commit_company"){
                    $("#input_company").attr("checked","checked");
                    $("#commit_company").children().addClass("checked");
                }
            }
        }
        //设置按钮文本
        document.getElementById('textfield').value = data.buttonText;
        //设置按钮颜色
        document.getElementById('btn_color').value = data.buttonCss;
        setTimeout(function () {
            //设置自定义文本内容信息
            var cktext_info = data.content;
            //CKEDITOR.instances.editor.setData(cktext_info);
            editor.setContent(cktext_info);
        }, 1000);
        //设置二维码
        if(StringEmpty(data.weiboQrcode)){
            choseQrWeiboFlag=true;
            weibo_qrcode=data.weiboQrcode;
            $('#input_weibo').parent().addClass("checked");
            $("#input_weibo").attr("checked","checked");
            document.getElementById('img5').src = data.weiboQrcode;
            document.getElementById('erweima_weibo2').src = data.weiboQrcode;

        }
        if(StringEmpty(data.weixinQrcode)){
            weixin_qrcode=data.weixinQrcode;
            choseQrWeixinFlag=true;
            document.getElementById('img4').src = data.weixinQrcode;
            $('#input_weixin').parent().addClass("checked");
            $("#input_weixin").attr("checked","checked");
            document.getElementById('erweima_weixin2').src = data.weixinQrcode;
        }
        sms_content=data.smsContent
        if(StringEmpty(sms_content))
            $('#sms_content').val(sms_content);
        if(StringEmpty(data.remarks)){
            $('#bgd_color').val(data.remarks);
            reloadBackground();
        }
        reloadLeft();
    }
    function save() {
        //获取输入的活动标题
        title=document.getElementById("firstname").value;
        button_color=document.getElementById("btn_color").value;
        button_text=document.getElementById("textfield").value;
        /*lg*/
        /*text_info=CKEDITOR.instances.editor.getData();*/
        text_info=editor.getContent();

        sms_content=$('#sms_content').val();
        activityTag=$('#activity_tag').val();
        if(StringEmpty(send_type) && !StringEmpty(sms_content)){
            errorDialog("情输入短信文本内容");
            return;
        }
        if(!choseQrWeixinFlag)
            weixin_qrcode="";
        if(!choseQrWeiboFlag)
            weibo_qrcode="";

        if(couponFlag == 1){
            couponModelIds=thirdPartyCouponIds.join(",");
        }else{
            couponModelIds=couponIds.join(",");
        }
        if(next_flag||type=="model"||type=="model_copy"){
            if(StringEmpty(title)&&title.length<26&&StringEmpty(text_info)){
                if(type=="model"){
                    if(!StringEmpty(model_id)&&!save_tag){
                        createModle();
                    }else{
                        editModel();
                    }

                }else if(type=="activity"){
                    if(!StringEmpty(activity_id)&&!save_tag){

                        createActivity();
                    }else{

                        editActivity();
                    }
                }else if(type=="model_copy"){
                    if(save_tag){
                        editModel();
                    }else{
                        createModle();
                    }
                }else if(type=="activity_copy"){
                    if(save_tag){
                        editActivity();
                    }else{
                        createActivity();
                    }
                }else if(type=="both"){
                    if(!StringEmpty(model_id)&&!save_tag){
                        createModle();
                    }else{
                        editModel();
                    }
                }
            }else if(!StringEmpty(title)){
                errorDialog("请输入名称","");
                next_flag=false;
            }else if(title.length>20){
                errorDialog("主题不能超过20个字","");
                next_flag=false;
            }else if(!StringEmpty(text_info)){
                errorDialog("请设计模板样式","");
                next_flag=false;
            }
        }else{

            if(!StringEmpty(title)){
                errorDialog("请输入名称");
                next_flag=false;
                return ;
            }
            if(StringEmpty(commit_info) && commit_info.indexOf("commit_mobile")==-1){
                errorDialog("请勾选手机号码！","");
                return ;
            }
            if(type=="model"){
                if(!StringEmpty(model_id)&&!save_tag){
                    createModle();
                }else{
                    editModel();
                }

            }else if(type=="activity"){
                if(!StringEmpty(activity_id)&&!save_tag){
                    createActivity();
                }else{

                    editActivity();
                }
            }else if(type=="model_copy"){
                if(save_tag){
                    editActivity();
                }else{
                    createActivity();
                }
            }else if(type=="activity_copy"){
                status="2";
                if(save_tag){
                    editActivity();
                }else{
                    createActivity();
                }
            }else if(type=="both"){
                if(!StringEmpty(model_id)&&!save_tag){
                    createModle();
                }else{
                    editModel();
                }
            }
        }

    }
    //创建模板
    function createModle(){
        var url = "<%=path%>/activityDefinedTemplate/ajaxCreateTemplate";
        $.post(url, {
            "content" : text_info,
            "collectInfo" : commit_info,
            "buttonCss" : button_color,
            "buttonText" : button_text,
            "name" : title,
            "type" : "defined_text",
            "weixinQrcode" : weixin_qrcode,
            "weiboQrcode" : weibo_qrcode,
            "customSmsText":sms_content,
            "bgColor":background_color,
        }, function(data) {

            if (data.status == 200) {
                model_id=data.data;
                save_tag=true;
                saveModelAc();
            } else {
                errorDialog(data.message,"");
            }
        });
    }
    //编辑模板
    function editModel() {
        var url = "<%=path%>/activityDefinedTemplate/ajaxEditTemplate";
        $.post(url, {
            "id":model_id,
            "content" : text_info,
            "collectInfo" : commit_info,
            "buttonCss" : button_color,
            "buttonText" : button_text,
            "name" : title,
            "type" : "defined_text",
            "weixinQrcode" : weixin_qrcode,
            "weiboQrcode" : weibo_qrcode,
            "customSmsText":sms_content,
            "bgColor":background_color,
        }, function(data) {
            if (data.status == 200) {
                save_tag=true;
                saveModelAc();
            } else {
                errorDialog(data.message,"");
            }
        });
    }
    //活动创建标记  防止重复创建
    var createActivityFlag=true;
    //创建活动
    function createActivity(){
        if(!createActivityFlag){
            return ;
        }
        createActivityFlag=false;
        var url = "<%=path%>/activity/ajaxCreateActivity";
        $.post(url, {
            "access_token" :access_token,
            "uid" : uid,
            "name" : title,
            "modelId" : model_id,
            "commitInfo" : commit_info,
            "weixinQrcode" : weixin_qrcode,
            "weiboQrcode" : weibo_qrcode,
            "activityType" : "defined_text",
            "description" : text_info,
            "buttonCss" : button_color,
            "buttonText" : button_text,
            "smsContent":sms_content,
            "status":status,
            "couponName":couponName,
            "couponModelIds":couponModelIds,
            "tagDefined":activityTag,
            "couponSendType" : send_type,
            "couponFlag":couponFlag,
            "activityTemplateType":modelType,
        }, function(data) {
            if (data.status == 200) {
                activity_id=data.data.activityId;
                save_tag=true;
                save_actiivty_tag=true;
                saveStoreAc();
            } else {
                errorDialog(data.message,"");
            }
            createActivityFlag=true;
        });
    }
    //编辑活动
    function editActivity() {
        var url = "<%=path%>/activity/ajaxEditActivity";
        $.post(url, {
            "id":activity_id,
            "access_token" :access_token,
            "uid" : uid,
            "name" : title,
            "modelId" : model_id,
            "commitInfo" : commit_info,
            "weixinQrcode" : weixin_qrcode,
            "weiboQrcode" : weibo_qrcode,
            "tag" : "defined_text",
            "description" : text_info,
            "buttonCss" : button_color,
            "buttonText" : button_text,
            "smsContent":sms_content,
            "status":status,
            "couponName":couponName,
            "couponModelIds":couponModelIds,
            "tagDefined":activityTag,
            "couponSendType" : send_type,
            "couponFlag":couponFlag,
        }, function(data) {
            if (data.status == 200) {
                save_tag=true;
                save_actiivty_tag=true;
                saveStoreAc();
            } else {
                errorDialog(data.message,"");
            }
        });
    }

    $('input[name=filepath]').change(function () {
        var fileCount = this.files.length;
        var type=$(this).attr('fileType');
        if(fileCount!=0){
            fileloadon(type);
        }
    })

    var flag=false;
    function fileloadon(upload_type) {
        $("#_weixin_qrcode").submit(function () {
            if(flag){
                return ;
            }
            flag=true;
            $("#_weixin_qrcode").ajaxSubmit({
                type: "post",
                url: "${pageContext.request.contextPath}/api/uploadfile/file",
                data:{"typename":"filepath"},
                success: function (data1) {
                    weixin_qrcode=data1.realSavePath;
                    $("#img4").attr('src',weixin_qrcode);
                    $("#erweima_weixin2").attr('src',weixin_qrcode);
                    $('#input_weixin').parent().addClass("checked");
                    $("#input_weixin").attr("checked","checked");
                    choseQrWeixinFlag=true;
                    reloadLeft();
                },
                error: function (msg) {
                    errorDialog("文件上传失败","");
                }
            });
            return false;
        });

        $("#_weibo_qrcode").submit(function () {
            if(flag){
                return ;
            }
            flag=true;
            $("#_weibo_qrcode").ajaxSubmit({
                type: "post",
                url: "${pageContext.request.contextPath}/api/uploadfile/file",
                data:{"typename":"filepath"},
                success: function (data1) {

                    weibo_qrcode=data1.realSavePath;
                    $("#img5").attr('src',weibo_qrcode);
                    $("#erweima_weibo2").attr('src',weibo_qrcode);
                    $('#input_weibo').parent().addClass("checked");
                    $("#input_weibo").attr("checked","checked");
                    choseQrWeiboFlag=true;
                    reloadLeft();
                },
                error: function (msg) {
                    errorDialog("文件上传失败","");
                }
            });
            return false;
        });
        switch (upload_type) {
            case "weixin":
                flag=false;
                $("#_weixin_qrcode").submit();
                break;
            case "weibo":
                flag=false;
                $("#_weibo_qrcode").submit();
                break;

            default:
                break;
        }

    }
    //门店id
    var id;
    function colseModal(){
        $('#store_modal').modal('hide');
    }

    function determineStore(){
        /* store_names.length=0;
        store_ids.length=0; */
        <%--         	$("#bm_cstore .x_CheckBox[src$='s_check.png']").each(
                            function(i, d) {
                                var name = $(this).attr("cname");
                                store_names[i]=name;
                                store_ids[i]=this.id;
                    });
                    var html='';
                    for(var i in store_names){
                        html += '<li id="store_line'+i+'" indexNum="'+i+'" class="delete_md_detail col-md-6 text-left" cid="'+store_names[i]+'" >'+store_names[i]+'<img indexNum="'+i+'" cid="'+store_names[i]+'" id="delete_store" src="<%=path%>/images/marketing/close.png" class="x_lista"></li>';
                    }
                    $('#bm_md_list').html(html);  --%>
        var html='';
        for(var i in store_names){
            html += '<li id="store_line'+i+'" indexNum="'+i+'" class="delete_md_detail  col-md-6 text-left" cid="'+store_names[i]+'" >'+store_names[i]+'<img indexNum="'+i+'" cid="'+store_names[i]+'" id="delete_store" src="<%=path%>/images/marketing/close.png" class="x_lista"></li>';
        }
        $('#bm_md_list').html(html);
        $('#store_modal').modal('hide');
    }


    //打叉移除选择的门店
    $(document).on('click','#delete_store',function(){
        var index=$(this).attr("indexNum");
        var storeName=$(this).attr("cid");
        var lineId="#store_line"+$(this).attr("indexNum");
        $(lineId).remove();
        store_ids.splice(index,1);
        store_names.splice(contains(store_names,storeName), 1);
    });
    //打叉移除选择的优惠券
    $(document).on('click','.delCouponModel',function(){
        var index=$(this).attr("indexNum");
        var lineId="#couponModelline"+$(this).attr("indexNum");
        $(lineId).remove();
        if(couponModelType == 1){
            thirdPartyCouponIds.splice(contains(thirdPartyCouponIds,index), 1);
            thirdCouponNameMap.delete(index);
        }else{
            couponIds.splice(contains(couponIds,index), 1);
            couponNameMap.delete(index);
        }
        couponIdsMap.delete(index);
    });
    //获取活动门店信息
    function activityStore(){
        var url = "<%=path%>/activityStore/ajaxListRelationActivityStore";
        $.post(url,{
            "activityId" : activity_id,
        },function(data){
            if(data.status == "200"){
                var stores=data.data;
                var html='';
                for(var i in stores){
                    store_ids[i]=stores[i].id;
                    store_names[i]=stores[i].name;
                    html += '<li id="store_line'+i+'" indexNum="'+i+'" class="delete_md_detail col-md-6 text-left" cid="'+store_names[i]+'" >'+store_names[i]+'<img indexNum="'+i+'" cid="'+store_names[i]+'" id="delete_store" src="<%=path%>/images/marketing/close.png" class="x_lista"></li>';
                }
                $('#bm_md_list').html(html);
            }else{

            }
        });
    }
    //获取模板的门店信息
    function modelStore(){
        var url = "<%=path%>/activityDefinedTemplate/ajaxListRelationActivityStore";
        $.post(url,{
            "templateId" : model_id,
        },function(data){
            if(data.status == "200"){
                var stores=data.data;
                var html='';
                for(var i in stores){
                    store_ids[i]=stores[i].id;
                    store_names[i]=stores[i].name;
                    html += '<li id="store_line'+i+'" indexNum="'+i+'" class="delete_md_detail col-md-6 text-left" cid="'+store_names[i]+'" >'+store_names[i]+'<img indexNum="'+i+'" cid="'+store_names[i]+'" id="delete_store" src="<%=path%>/images/marketing/close.png" class="x_lista"></li>';
                }
                $('#bm_md_list').html(html);
            }else{

            }
        });
    }
    //保存用戶选择的门店
    function saveStoreAc(){
        var storeIds=splitIds(store_ids.join(","));
        var url = "<%=path%>/activityStore/ajaxInsertBatch";
        $.post(url,{
            "activityId" : activity_id,
            "storeIds" : storeIds,
        },function(data){
            if(next_flag){
                $.cookie(activity_id, title);
                window.location.href = "<%=path%>/view/ui/createActivitySuccessPage?activityId="+activity_id+"&type="+operationType;
            }else{
                successDialog("暂存成功","");
                if(data.error_code == "0"){
                }else{
                }
            }
        });
    }


    //保存用戶选择的门店-----模板
    function saveModelAc(){
        var storeIds=splitIds(store_ids.join(","));
        var url = "<%=path%>/activityDefinedTemplate/ajaxSaveStore";
        $.post(url,{
            "templateId" :model_id,
            "storeIds" : storeIds,
        },function(data){
            if(next_flag){
                window.location.href = "<%=path%>/view/ui/activityTemplatePreview?model_id="+model_id;
            }else{
                successDialog("保存成功","");
            }
        });
    }

    function determineCoupon(){
        couponFlag=tempCouponModelType;
        var html='';
        if(couponFlag == 1){
            couponIds.length=0;
            if(thirdPartyCouponIds.length>10){
                errorDialog("最多只能选择10个优惠券");
                return ;
            }
            thirdCouponNameMap.forEach(function (element, index, array) {
                html += '<li id="couponModelline'+index+'" indexNum="'+index+'" class="delete_md_detail  col-md-6 text-left" >'+element+'<img indexNum="'+index+'" cid="'+index+'" src="<%=path%>/images/marketing/close.png" class="x_lista delCouponModel"></li>';
            });
            $('#couponModelList').html(html);
        }else{
            thirdPartyCouponIds.length=0;
            if(couponIds.length>10){
                errorDialog("最多只能选择10个优惠券");
                return ;
            }
            couponNameMap.forEach(function (element, index, array) {
                html += '<li id="couponModelline'+index+'" indexNum="'+index+'" class="delete_md_detail  col-md-6 text-left" >'+element+'<img indexNum="'+index+'" cid="'+index+'" src="<%=path%>/images/marketing/close.png" class="x_lista delCouponModel"></li>';
            });
            $('#couponModelList').html(html);
        }
        colseCouponModal();
    }

    function colseCouponModal(){
        couponModalStatus=false;
        $('#coupon_modal').modal('hide');
    }


    //获取参数
    function getQueryString(name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        if (r != null)
            return unescape(r[2]);
        return null;
    }

    //判断字符串是否为空
    function StringEmpty(content) {
        if (content == undefined || content == "" || content == null) {
            return false;
        } else {
            return true;
        }
    }


    $('#x_button_l').click(function () {
        if(type=="model"&&StringEmpty(model_id)){
            history.go(-1);
        }else if(type=="model"){
            history.go(-1);
        }else{
            window.location.href="<%=path%>/view/ui/activityHome";
        }
    });
    //取消编辑
    function cancelModelEdit(){
        var url = "<%=path%>/activityDefinedTemplate/ajaxUnlockTemplate";
        $.post(url,{
            "id" : id,
        },function(data){
        });
    }



    function intentCreateActivity(){
        window.location.href = "<%=path%>/view/ui/createModel?type=activity&model_id="+model_id;
    }
    //监听后退
    function pushHistory() {
        var state = {
            title: "title",
            url: "#"
        };
        window.history.pushState(state, "title", "#");
    }
    //监听离开页面
    document.onclick = function (event)

    {

        var e = event || window.event;

        var elem = e.srcElement||e.target;

        while(elem){
            if(elem.id == "menuContent"||elem.id =="more_but") {
                return;
            }
            elem = elem.parentNode;
        }
        upd();
    }
    function upd(){
        if(type=="model"&&StringEmpty(model_id)){
            //cancelModelEdit();
        }else if(StringEmpty(activity_id)){
            // unLockActivity();
        }
    }
    function unLockActivity(){
        <%-- var url= "<%=path%>/activity/ajaxUnlockActivity";
        $.post(url, {
            "access_token" : access_token,
            "cid" : cid,
            "uid" : uid,
            "activityId" : activity_id,
        }, function(data) {

        }); --%>
    }

    function splitIds(ids){
        var result="";
        var idstemp=ids.split(',');
        for(var i in idstemp){
            if(!isNaN(idstemp[i])&&idstemp[i]>0){
                result=result+","+idstemp[i];
            }
        }
        result=result.replace(",","");
        return result;
    }

    $("#coupon_modal").on("hide.bs.modal", function() {
        if(couponModalStatus){
            return ;
        }
        $(this).removeData("bs.modal");
        $('#coupon_modal .modal-content').empty();
    });
    $("#store_modal").on("hidden.bs.modal", function() {
        $(this).removeData("bs.modal");
        $('#store_modal .modal-content').empty();
    });

    $(document).on('click','#bm_cstore img',function(){
        var src = $(this).attr("src");
        mdstore="";
        if(src=="<%=path%>/images/marketing/s_check_no.png"){
            $(this).attr("src","<%=path%>/images/marketing/s_check.png");
            name = $(this).attr("cname");
            store_names.push(name);
            store_ids.push(this.id);
        }else{
            $(this).attr("src","<%=path%>/images/marketing/s_check_no.png");
            name = $(this).attr("cname")+"";
            store_names.splice(contains(store_names,name), 1);
            store_ids.splice(contains(this.id,store_ids), 1);
        }

    });
</script>
</body>
</html>
